package com.ruoyi.web.controller.sys.workHour;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BusiDeptWorkhour;
import com.ruoyi.system.service.BusiDeptWorkhourService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;
import java.util.GregorianCalendar;

@Api("部门工时管理")
@RestController
@RequestMapping("/sys/DeptWorkHour")
public class deptWorkHourController extends BaseController {
    @Autowired
    BusiDeptWorkhourService busiDeptWorkhourService;

    @ApiOperation("显示所有分组的基准值")
    @PostMapping("/show")
    public TableDataInfo show() {
        //开启分页
        startPage();
        //查询所有
        return getDataTable(busiDeptWorkhourService.showAll());
    }

    @ApiOperation("显示当前月份所有分组的基准值")
    @PostMapping("/showNow")
    public TableDataInfo showNow() {
        //开启分页
        startPage();
        //获取当前月份
        Calendar calendar = new GregorianCalendar();
        int month = calendar.get(Calendar.MONTH) + 1;
        //根据月份查找
        return getDataTable(busiDeptWorkhourService.showNow(String.valueOf(month)));
    }

    @ApiOperation("分组基准值的修改")
    @PostMapping("/update")
    @Log(title = "分组基准值的修改", businessType = BusinessType.UPDATE)
    public AjaxResult update(@RequestBody BusiDeptWorkhour busiDeptWorkhour) {
        //判断是否数据是否合法
        if (busiDeptWorkhour.getRemarks() != null && busiDeptWorkhour.getTargetWorkhours() != null) {
            //进行修改操作
            return AjaxResult.success(busiDeptWorkhourService.update(busiDeptWorkhour));
        } else {
            //返回错误状态码
            return AjaxResult.error(busiDeptWorkhour.getDeptName() + "分组基准值非法");
        }
    }
}

